package com.apexsoft.monitor.front.console.sill.controller;

import com.alibaba.fastjson.JSONObject;
import com.apexsoft.front.common.support.BaseFrontController;
import com.apexsoft.front.common.utils.annotation.CrudMethod;
import com.apexsoft.monitor.front.console.aop.AopAnnotation;
import com.apexsoft.monitor.front.console.pageModel.SillModel;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.apexsoft.monitor.front.console.sill.service.SillService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller("sillController")
@RequestMapping("/console/sill")
public class SillController extends BaseFrontController {
    @Autowired
    @Qualifier("sillService")
    private SillService sillService = null;
    /**
     * 主机监控
     */
    @RequestMapping(value = "/list")
    public String list(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
        return "console/sill/list";
    }

    @RequestMapping(value = "/loadSillByPage")
    public String getEsbNodes(HttpServletRequest request, HttpServletResponse response,@ModelAttribute("form") SillModel sillModel) throws Exception {
        Pagination page =new Pagination(sillModel.getPageNum(),sillModel.getPageSize());
        JSONObject result = this.sillService.listByPage(page,sillModel);
        this.printJSON(response, result);
        return null;
    }

    @CrudMethod
    @AopAnnotation(description="添加阀值")
    @RequestMapping(value = "/add")
    public String add(HttpServletRequest request, HttpServletResponse response) throws Exception {

        JSONObject result = sillService.add(request);
        this.printJSON(response, result);
        return null;

    }

    @CrudMethod
    @AopAnnotation(description="修改阀值信息")
    @RequestMapping(value = "/update")
    public String update(HttpServletRequest request, HttpServletResponse response) throws Exception {

        JSONObject result = sillService.update(request);
        this.printJSON(response, result);
        return null;

    }

    @CrudMethod
    @AopAnnotation(description="根据id删除节点")
    @RequestMapping(value = "/delete")
    public String delete(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String id = request.getParameter("id");
        JSONObject result = sillService.delete(id);
        this.printJSON(response, result);
        return null;

    }

}
